//
//  CJHUD+CJ.m
//
//  Created by Chen_Jun on 2017/6/28.
//  Copyright © 2017年 zwu. All rights reserved.
//

#import "CJHUD+DIY.h"
#define hideTime 1.0

@implementation CJHUD (DIY)
#pragma mark 显示信息
+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
{
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    CJHUD *hud = [CJHUD showHUDAddedTo:view animated:YES];
    hud.labelText = text;
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"CJHUD.bundle/%@", icon]]];
    // 再设置模式
    hud.mode = CJHUDModeCustomView;
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    // 1秒之后再消失
    [hud hide:YES afterDelay:hideTime];
}





#pragma mark 显示 自定义类型 信息
+ (void)showHUDText:(NSString *)text forHUDType:(HUDType)HUDType toView:(UIView *)view
{
    NSString *icon = nil;
    switch (HUDType)
    {
        case HUDTypeNull:    icon = nil;          break;
        case HUDTypeSuccess: icon = @"success.png"; break;
        case HUDTypeError:   icon = @"error.png"; break;
        case HUDTypeSmile:   icon = @"smile.png"; break;
        case HUDTypeCry:     icon = @"cry.png";   break;
        default:                                  break;
    }
    [self show:text icon:icon view:view];
}
+ (void)showHUDText:(NSString *)text forHUDType:(HUDType)HUDType
{
    [self showHUDText:text forHUDType:HUDType toView:nil];
}









#pragma mark 显示 "旋转-菊花" 信息
+ (CJHUD *)showMessage:(NSString *)message toView:(UIView *)view
{
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    CJHUD *hud = [CJHUD showHUDAddedTo:view animated:YES];
    hud.labelText = message;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
    hud.diCJackground = YES;
    return hud;
}
+ (CJHUD *)showMessage:(NSString *)message
{
    return [self showMessage:message toView:nil];
}






#pragma mark - hideHUDForView
+ (void)hideHUDForView:(UIView *)view
{
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    [self hideHUDForView:view animated:YES];
}
#pragma mark - hideHUD
+ (void)hideHUD
{
    [self hideHUDForView:nil];
}




@end





